<!--
 * @Author: your name
 * @Date: 2023-02-24 17:55:58
 * @LastEditTime: 2023-02-24 18:01:03
 * @LastEditors: DESKTOP-0ELIMBF
 * @Description: In User Settings Edit
 * @FilePath: \interview-questions\interview_after_graduation\例子\sleep.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // js实现阻塞5秒执行
        //方法1
        function sleep(time){
            let nowTime = new Date().getTime()
            while(new Date().getTime() - nowTime < time){
                console.log(nowTime,new Date().getTime() - nowTime)
                continue;
            }
            let endTime = new Date().getTime()
            console.log(nowTime,endTime,endTime - nowTime,'done')
        }
        sleep(5000)
        //方法2
        setTimeout(()=>{
            console.log("hhh")
        },5000)
    </script>
</head>
<body>
    
</body>
</html>